﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;

namespace ScormModel
{
    [Serializable()]
    public class Objective
    {
        private string _objectiveID;
        private string _satisfiedByMeasure;
        private string _minNormalizedMeasure;
        private List<MapInfo> _listMapInfo;
         [NonSerialized]
        private XmlNode _objectiveContent;
        [XmlAttribute("objectiveID")]
        public string ObjectiveID
        {
            get { return this._objectiveID; }
            set { this._objectiveID = value; }
        }
        [XmlAttribute("satisfiedByMeasure")]
        public string SatisfiedByMeasure
        {
            get { return this._satisfiedByMeasure; }
            set { this._satisfiedByMeasure = value; }
        }
        [XmlElement("minNormalizedMeasure")]
        public String MinNormalizedMeasure
        {
            get { return this._minNormalizedMeasure; }
            set { this._minNormalizedMeasure = value; }
        }
        [XmlElement("mapInfo", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<MapInfo> ListMapInfo
        {
            get { return this._listMapInfo; }
            set { this._listMapInfo = value; }
        }
        
        [XmlIgnoreAttribute]
        public XmlNode ObjectiveContent
        {
            get { return this._objectiveContent; }
            set { this._objectiveContent = value; }
        }
        public void buildObjective()
        {
            XmlAttributeCollection attList = _objectiveContent.Attributes;
            _listMapInfo = new List<MapInfo>();
            if (attList.GetNamedItem("objectiveID") != null)
            {
                _objectiveID = ((XmlAttribute)attList.GetNamedItem("objectiveID")).Value;
            }
            if (attList.GetNamedItem("satisfiedByMeasure") != null)
            {
                _satisfiedByMeasure = ((XmlAttribute)attList.GetNamedItem("satisfiedByMeasure")).Value;
            }
            for (int i = 0; i < _objectiveContent.ChildNodes.Count; i++)
            {
                if (_objectiveContent.ChildNodes[i].Name == "imsss:minNormalizedMeasure")
                {
                    _minNormalizedMeasure = (_objectiveContent.ChildNodes[i]).InnerText;
                }
                if (_objectiveContent.ChildNodes[i].Name == "imsss:mapInfo")
                {
                    MapInfo mapInfo = new MapInfo();
                    mapInfo.MapInfoContent = _objectiveContent.ChildNodes[i];
                    mapInfo.buildMapInfo();
                    _listMapInfo.Add(mapInfo);
                }
            }
        }
    }
}
